/**
 * @title as3缩放工具的自定义绘制鼠标样式类库
 * */

package com.tongji.showroom.view.twoD{
	import flash.display.Shape;
	import flash.ui.Mouse;
	
	public class TransformCursor extends Shape{
		/**水平移动时的光标样式*/
	    public static const LEFTRIGHT:String = "lr";
		/**垂直移动时的光标样式*/
		public static const TOPBOTTOM:String = "tb";
		/**(顶角上)宽高同时变时(正斜型)的光标样式*/
		public static const ZHENGXIE:String = "zx";
		/**(顶角上)宽高同时变时(反斜型)的光标样式*/
		public static const FANXIE:String = "fx";
		/**拖拽时的光标样式*/
		public static const DRAG:String = "dg";
		/**还原鼠标的默认样式*/
		public static const NORMAL:String = "";
		
        public function TransformCursor():void{
			
	    }
		
		/**
		 * 设置光标的样式
		 * @param s 把光标设置成何种样式
		 * */
		public function set setCursor(s:String):void{
			Mouse.hide();
			superDraw();
			this.rotation = 0;
		    if(s == LEFTRIGHT){    //水平移动时的光标样式
				zhi(0);
			}else if(s == TOPBOTTOM){    //垂直移动时的光标样式
				zhi(90);
			}else if(s == ZHENGXIE){    //(顶角上)宽高同时变时(正斜型)的光标样式
				zhi(-45);
			}else if(s == FANXIE){    //(顶角上)宽高同时变时(反斜型)的光标样式
				zhi(45);
			}else if(s == DRAG){    //拖拽时的光标样式
				drag();
			}else{    //还原鼠标的默认样式
			    Mouse.show();
				this.graphics.clear();
			}
		}
		 
		/**公共代码*/
		private function superDraw():void{
		    this.graphics.beginFill(0xFFFFFF);    //光标样式的填充颜色
			this.graphics.lineStyle(1, 0x000000);    //光标样式的边框颜色
		}
		
		/**水平或垂直移动时的光标样式*/
		private function zhi(r:Number):void{
			this.rotation = r;
		    /*右侧箭头*/
			this.graphics.moveTo(0, -2);    //初始位置
			this.graphics.lineTo(6, -2);    //初始位置
			this.graphics.lineTo(6, -6);
			this.graphics.lineTo(11, -0.5);
			this.graphics.lineTo(6, 5);
			this.graphics.lineTo(6, 1);
			this.graphics.lineTo(0, 1);
			 /*左侧箭头*/
			this.graphics.moveTo(0, -2);    //初始位置
			 this.graphics.lineTo(-6, -2);
			 this.graphics.lineTo(-6, -6);
			 this.graphics.lineTo(-11, -0.5);
			 this.graphics.lineTo(-6, 5);
			 this.graphics.lineTo(-6, 1);
			 this.graphics.lineTo(0, 1);
			 this.graphics.endFill();
		 }
		 
		 /**(顶角上)宽高同时变时的光标样式*/
		 private function xie(r:Number):void{
			 this.rotation = r;
			 this.graphics.moveTo(-6, -1);
			 this.graphics.lineTo(6, -1);
			 this.graphics.lineTo(6, -4);
			 this.graphics.lineTo(10, 1);
			 this.graphics.lineTo(-6, 1);
			 this.graphics.lineTo(-6, -1);
			 this.graphics.endFill();
			 superDraw();    //公共代码
			 //left arrow
			 this.graphics.moveTo(10, 5);
			 this.graphics.lineTo(-2, 5);
			 this.graphics.lineTo(-2, 8);
			 this.graphics.lineTo(-6, 3);
			 this.graphics.lineTo(10, 3);
			 this.graphics.lineTo(10, 5);
			 this.graphics.endFill();
		 }
		 
		 /**拖拽时的光标样式*/
		 private function drag():void{
			 /*上面的箭头*/
			 this.graphics.moveTo(1, 1);
			 this.graphics.lineTo(1, -5);
			 this.graphics.lineTo(-3, -5);
			 this.graphics.lineTo(2, -9);
			 this.graphics.lineTo(7, -5);
			 this.graphics.lineTo(3, -5);
			 this.graphics.lineTo(3, 1);
			 /*右面的箭头*/
			 this.graphics.lineTo(9, 1);
			 this.graphics.lineTo(9, -3);
			 this.graphics.lineTo(14, 2);
			 this.graphics.lineTo(9, 7);
			 this.graphics.lineTo(9, 3);
			 this.graphics.lineTo(3, 3);
			 /*下面的箭头*/
			 this.graphics.lineTo(3, 7);
			 this.graphics.lineTo(8, 7);
			 this.graphics.lineTo(2, 12);
			 this.graphics.lineTo(-3, 7);
			 this.graphics.lineTo(1, 7);
			 this.graphics.lineTo(1, 3);
			 /*左面的箭头*/
			 this.graphics.lineTo(-5, 3);
			 this.graphics.lineTo(-5, 7);
			 this.graphics.lineTo(-9, 2);
			 this.graphics.lineTo(-5, -3);
			 this.graphics.lineTo(-5, 1);
			 this.graphics.lineTo(1, 1);
			 this.graphics.endFill();
		 }
		 
		 /**旋转时的光标样式*/
		 private function rotationStyle():void{
			 //curve
			 var angle1:Number = Math.PI;
			 var angle2:Number = -Math.PI / 2;
			 drawArc(0,0,4, angle1, angle2);
			 drawArc(0,0,6, angle2, angle1, false);
			 //arrow
			 this.graphics.lineTo(-8, 0);
			 this.graphics.lineTo(-5, 4);
			 this.graphics.lineTo(-2, 0);
			 this.graphics.lineTo(-4, 0);
			 this.graphics.endFill();
		 }
		 
		 /**旋转时的光标样式详细处理*/
		 private function drawArc(originX:Number, originY:Number, radius:Number, angle1:Number, angle2:Number, useMove:Boolean = true):void {
			 var diff:Number = angle2 - angle1;
			 var divs:Number = 1 + Math.floor(Math.abs(diff)/(Math.PI/4));
			 var span:Number = diff/(2*divs);
			 var cosSpan:Number = Math.cos(span);
			 var radiusc:Number = cosSpan ? radius/cosSpan : 0;
			 var i:int;
			 if(useMove){
				 this.graphics.moveTo(originX + Math.cos(angle1) * radius, originY - Math.sin(angle1) * radius);
			 }else{
				 this.graphics.lineTo(originX + Math.cos(angle1) * radius, originY - Math.sin(angle1) * radius);
			 }
			 for(i = 0; i < divs; i++){
				 angle2 = angle1 + span;
				 angle1 = angle2 + span;
				 this.graphics.curveTo(
					 originX + Math.cos(angle2) * radiusc, originY - Math.sin(angle2) * radiusc,
					 originX + Math.cos(angle1) * radius, originY - Math.sin(angle1) * radius
				 );
			 }
		 }
		 
	}
}